package com.walterlife.asynserv;

import org.apache.log4j.Logger;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.CharsetUtil;

public class DiscardServerHandler extends ChannelHandlerAdapter {

    private Logger logger = Logger.getLogger(DiscardServerHandler.class);

    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        logger.info("enter");
        ByteBuf in = (ByteBuf)msg;
        try {
            logger.info("recv msg " + in.toString(CharsetUtil.US_ASCII));
        } finally {
            ((ByteBuf)msg).release();
        }
    } 

    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    } 
}
